package cn.ztuo.bitrade.controller.awardsSetting;

import cn.ztuo.bitrade.annotation.AccessLog;
import cn.ztuo.bitrade.constant.AdminModule;
import cn.ztuo.bitrade.constant.SysConstant;
import cn.ztuo.bitrade.controller.BaseController;
import cn.ztuo.bitrade.entity.Admin;
import cn.ztuo.bitrade.entity.AwardsSetting;
import cn.ztuo.bitrade.service.AwardsSettingService;
import cn.ztuo.bitrade.util.MessageResult;
import cn.ztuo.bitrade.vo.AwardsSettingVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

/**
 * @author: Xiazt
 * @date: 2020-04-22 16:32
 */
@RestController
@RequestMapping("awardsSetting")
public class AwardsSettingController extends BaseController {

    @Autowired
    private AwardsSettingService awardsSettingService;

    @RequiresPermissions("awardsSetting:page-query")
    @RequestMapping(value = "page-query")
    @AccessLog(module = AdminModule.AWARDSSETTING, operation = "分页获取奖金设置")
    public MessageResult getByPage(AwardsSettingVO awardsSettingVO){
        return success(awardsSettingService.getByPage(awardsSettingVO));
    }

    @RequiresPermissions("awardsSetting:save")
    @RequestMapping(value = "saveOrUpdate")
    @AccessLog(module = AdminModule.AWARDSSETTING, operation = "添加或修改奖金设置")
    public MessageResult saveOrUpdate(@SessionAttribute(SysConstant.SESSION_ADMIN) Admin admin, AwardsSetting awardsSetting){
        AwardsSetting result = awardsSettingService.saveOrUpdate(awardsSetting);
        if (result == null) return error("服务器异常！");
        return success("操作成功");
    }

    @RequiresPermissions("awardsSetting:delete")
    @RequestMapping(value = "delete")
    @AccessLog(module = AdminModule.AWARDSSETTING, operation = "删除奖金设置")
    public MessageResult delete(@SessionAttribute(SysConstant.SESSION_ADMIN) Admin admin,Long id){
        awardsSettingService.deleteAwardsSetting(id);
        return success("删除成功");
    }

}
